package com.ag.utils.param.verify;

import org.apache.commons.lang.StringUtils;

import com.ag.exception.InvalidParamException;
import com.ag.utils.param.IVerifyAndConvertValue;

public class StringNotEmptyVerifyAndConvertValue implements IVerifyAndConvertValue {
	
	@Override
	public Object getValue(Object value, String viewName, Object defaultValue) {
		String valueOf = value == null ? null : String.valueOf(value);
		
		if (StringUtils.isBlank(valueOf)) {
			if(defaultValue != null) {
				return defaultValue;
			} else {
				throw new InvalidParamException(viewName + "值不能为空.");
			}
		} else {
			return valueOf;
		}
	}
}
